import sqlite3
import os

def check_tables():
    """检查数据库表结构"""
    
    db_path = os.path.join('app', 'esports.db')
    
    if not os.path.exists(db_path):
        print(f"数据库文件不存在: {db_path}")
        return
    
    print(f"连接数据库: {db_path}")
    conn = sqlite3.connect(db_path)
    cursor = conn.cursor()
    
    # 获取所有表
    cursor.execute("SELECT name FROM sqlite_master WHERE type='table';")
    tables = cursor.fetchall()
    print(f"数据库中的表: {[table[0] for table in tables]}")
    
    # 获取matches表结构
    print("\nmatches 表结构:")
    cursor.execute("PRAGMA table_info(matches)")
    columns = cursor.fetchall()
    for column in columns:
        print(f"  {column[1]} ({column[2]}), 默认值: {column[4]}")
    
    # 获取teams表结构
    print("\nteams 表结构:")
    cursor.execute("PRAGMA table_info(teams)")
    columns = cursor.fetchall()
    for column in columns:
        print(f"  {column[1]} ({column[2]}), 默认值: {column[4]}")
    
    # 获取matches表中的记录数
    cursor.execute("SELECT COUNT(*) FROM matches")
    count = cursor.fetchone()[0]
    print(f"\nmatches表中共有 {count} 条记录")
    
    # 获取teams表中的记录数
    cursor.execute("SELECT COUNT(*) FROM teams")
    count = cursor.fetchone()[0]
    print(f"teams表中共有 {count} 条记录")
    
    conn.close()

if __name__ == "__main__":
    check_tables() 